package guoanmaker.provider.business.controller;


import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.print.attribute.SetOfIntegerSyntax;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import guoanmaker.provider.business.model.PersonalInvoice;
import guoanmaker.provider.business.model.ReturnResult;
import guoanmaker.provider.business.modelnobind.ProvideOrderFormForOrder;
import guoanmaker.provider.business.modelnobind.SpaceReserve;
import guoanmaker.provider.business.modelnobind.UnreadOrderNum;
import guoanmaker.provider.business.service.ProvideOrderFormService;
import guoanmaker.provider.business.service.ProvideSpaceReserveService;
import guoanmaker.provider.helper.common.AjaxJson;
import guoanmaker.provider.helper.common.abstractobj.ApiController;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import redis.clients.jedis.Jedis;
/**
 * 
* @ClassName: ProvideOrderFormController 
* @Description: 订单controller
* @author Yvonne_MGL
* @date 2017年7月6日 下午3:24:07 
*  
 */
@RestController
@RequestMapping(ApiController.ORDER_FORM_URL)
public class ProvideOrderFormController {

	@Resource
	private ProvideOrderFormService provideOrderFormService;

	@Resource
	private AjaxJson ajaxJson;
	
	@Resource
	private ProvideSpaceReserveService provideSpaceReserveService;
	
	@Autowired  
	private  HttpServletRequest request;

	/**
	 * 
	* @Description: 根据条件查询服务商订单 
	* @param orderStatus 订单状态1待支付  2待接单  3服务中  4待确认   5退款处理中   6已完成   7已关闭
	* @param placeOrderTimeBegin 最早下单时间
	* @param placeOrderTimeEnd 最晚下单时间
	* @param priceBegin  最低价
	* @param priceEnd   最高价
	* @param commodityName  商品名称
	* @param pageNumber  分页页数 ,从0开始
	* @param pageSize  分页煤业条数
	* @author Yvonne_MGL 
	* @date 2017年7月6日 下午3:24:35     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "查询订单", notes = "查询订单")
	@RequestMapping(value = "/findByProperties", method = RequestMethod.POST)
	public AjaxJson findByProperties(String orderStatus, String placeOrderTimeBegin, String placeOrderTimeEnd,
			Double priceBegin, Double priceEnd, String commodityNameOrUserPhone, String businessid,Integer pageNumber, Integer pageSize) {
		Map orders = new HashMap();
		String sessionid=request.getSession().getId();
		String sessionid1=request.getHeader("Authorization");
		if(sessionid1!=null){
			sessionid=sessionid1.substring(7,sessionid1.length());
		}
		Jedis jedis=new Jedis("123.56.48.63",6379); 
		jedis.auth("218007");
		String value=jedis.get(sessionid);
		jedis.disconnect();
		if(value==null||!value.equals("1")){
			ajaxJson.setSuccess(false).setStatus(99).setMsg("请先登录").setData(orders);
		}else{
			try {
				orders = provideOrderFormService.findByProperties(orderStatus, placeOrderTimeBegin, placeOrderTimeEnd,
						priceBegin, priceEnd, commodityNameOrUserPhone, businessid,pageNumber, pageSize);
				ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(orders);
			} catch (Exception e) {
				ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(orders);
			}
		}
		
		return ajaxJson;

	}
	
	/**
	 * 
	* @Description: 根据订单id获取订单详情 
	* @param orderid 订单id
	* @param @return
	* @author Yvonne_MGL 
	* @date 2017年7月12日 上午11:38:05     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "查询订单详情", notes = "查询订单详情")
	@RequestMapping(value = "/findOrderForm", method = RequestMethod.POST)
	public AjaxJson findByid(String orderid){
		ProvideOrderFormForOrder order=new ProvideOrderFormForOrder();
		String sessionid=request.getSession().getId();
		String sessionid1=request.getHeader("Authorization");
		if(sessionid1!=null){
			sessionid=sessionid1.substring(7,sessionid1.length());
		}
		Jedis jedis=new Jedis("123.56.48.63",6379); 
		jedis.auth("218007");
		String value=jedis.get(sessionid);
		jedis.disconnect();
		if(value==null||!value.equals("1")){
			ajaxJson.setSuccess(false).setStatus(99).setMsg("请先登录").setData(order);
		}else{
			try {
				order=provideOrderFormService.findById(orderid);
				ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(order);
			} catch (Exception e) {
				ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(order);
			}
		}
		
		return ajaxJson;
	}
	
	/**
	 * 
	* @Description: 修改议价商品订单价格 
	* @param id 订单id
	* @param price 修改之后的价格
	* @param @return
	* @author Yvonne_MGL 
	* @date 2017年7月13日 上午9:52:37     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "修改议价商品订单价格", notes = "修改议价商品订单价格")
	@RequestMapping(value = "/modifyPrice", method = RequestMethod.POST)
	public AjaxJson modifyPrice(String id,Double price){
		ReturnResult returnResult=new ReturnResult();
		String sessionid=request.getSession().getId();
		String sessionid1=request.getHeader("Authorization");
		if(sessionid1!=null){
			sessionid=sessionid1.substring(7,sessionid1.length());
		}
		Jedis jedis=new Jedis("123.56.48.63",6379); 
		jedis.auth("218007");
		String value=jedis.get(sessionid);
		jedis.disconnect();
		if(value==null||!value.equals("1")){
			ajaxJson.setSuccess(false).setStatus(99).setMsg("请先登录").setData(returnResult);
		}else{
			try {
				returnResult=provideOrderFormService.modifyPrice(id, price);
				ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(returnResult);
			} catch (Exception e) {
				ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(returnResult);
			}
		}
		
		return ajaxJson;
	}
	
	/**
	 * 
	* @Description: 接单 
	* @param id  订单id
	* @param @return
	* @author Yvonne_MGL 
	* @date 2017年7月13日 上午10:21:54     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "接单", notes = "接单")
	@RequestMapping(value = "/acceptOrder", method = RequestMethod.POST)
	public AjaxJson acceptOrder(String id){
		ReturnResult returnResult=new ReturnResult();
		String sessionid=request.getSession().getId();
		String sessionid1=request.getHeader("Authorization");
		if(sessionid1!=null){
			sessionid=sessionid1.substring(7,sessionid1.length());
		}
		Jedis jedis=new Jedis("123.56.48.63",6379); 
		jedis.auth("218007");
		String value=jedis.get(sessionid);
		jedis.disconnect();
		if(value==null||!value.equals("1")){
			ajaxJson.setSuccess(false).setStatus(99).setMsg("请先登录").setData(returnResult);
		}else{
			try {
				returnResult=provideOrderFormService.acceptOrder(id);
				ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(returnResult);
			} catch (Exception e) {
				ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(returnResult);
			}
		}
		
		return ajaxJson;
	}
	
	/**
	 * 
	* @Description: 关闭待支付订单,拒绝已支付订单 
	* @param id 订单id
	* @param @return
	* @author Yvonne_MGL 
	* @date 2017年7月13日 上午10:51:12     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "关闭订单/放弃订单", notes = "关闭订单/放弃订单")
	@RequestMapping(value = "/closeOrder", method = RequestMethod.POST)
	public AjaxJson closeOrder(String id,String closeType,String beRefunds){
		ReturnResult returnResult=new ReturnResult();
		String sessionid=request.getSession().getId();
		String sessionid1=request.getHeader("Authorization");
		if(sessionid1!=null){
			sessionid=sessionid1.substring(7,sessionid1.length());
		}
		Jedis jedis=new Jedis("123.56.48.63",6379); 
		jedis.auth("218007");
		String value=jedis.get(sessionid);
		jedis.disconnect();
		if(!closeType.equals("4")&&(value==null||!value.equals("1"))){
			ajaxJson.setSuccess(false).setStatus(99).setMsg("请先登录").setData(returnResult);
		}else{
			try {
				returnResult=provideOrderFormService.closeOrder(id,closeType,beRefunds); 
				ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(returnResult);
			} catch (Exception e) {
				ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(returnResult);
			}
		}
		
		return ajaxJson;
	}
	
	/**
	 * 
	* @Description: 关闭待支付订单,拒绝已支付订单 
	* @param id 订单id
	* @param @return
	* @author Yvonne_MGL 
	* @date 2017年9月7日 下午8:49:03     
	* @return ReturnResult    
	* @throws 
	 */
	@ApiOperation(value = "关闭订单/放弃订单", notes = "关闭订单/放弃订单")
	@RequestMapping(value = "/closeOrderForOperator", method = RequestMethod.POST)
	public AjaxJson closeOrderForOperator(String id,Double amount){
		ReturnResult returnResult=new ReturnResult();
		try {
			returnResult=provideOrderFormService.closeOrderForOperator(id, amount);
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(returnResult);
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(returnResult);
		}
		
		return ajaxJson;
	}
	
	/**
	 * 
	* @Description: 服务商完成服务
	* @param id 订单id
	* @param @return
	* @author Yvonne_MGL 
	* @date 2017年7月13日 上午11:15:37     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "完成服务", notes = "完成服务")
	@RequestMapping(value = "/completeServe", method = RequestMethod.POST)
	public AjaxJson completeServe(String id){
		ReturnResult returnResult=new ReturnResult();
		String sessionid=request.getSession().getId();
		String sessionid1=request.getHeader("Authorization");
		if(sessionid1!=null){
			sessionid=sessionid1.substring(7,sessionid1.length());
		}
		Jedis jedis=new Jedis("123.56.48.63",6379); 
		jedis.auth("218007");
		String value=jedis.get(sessionid);
		jedis.disconnect();
		if(value==null||!value.equals("1")){
			ajaxJson.setSuccess(false).setStatus(99).setMsg("请先登录").setData(returnResult);
		}else{
			try {
				returnResult=provideOrderFormService.completeServe(id);
				ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(returnResult);
			} catch (Exception e) {
				ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(returnResult);
			}
		}
		
		return ajaxJson;
	}
	
	/**
	 * 
	* @Description: 完成退款
	* @param id 订单id
	* @param @return
	* @author Yvonne_MGL 
	* @date 2017年7月13日 下午2:04:40     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "完成退款", notes = "完成退款")
	@RequestMapping(value = "/confirmRefunds", method = RequestMethod.POST)
	public AjaxJson confirmRefunds(String id){
		ReturnResult returnResult=new ReturnResult();
		String sessionid=request.getSession().getId();
		String sessionid1=request.getHeader("Authorization");
		if(sessionid1!=null){
			sessionid=sessionid1.substring(7,sessionid1.length());
		}
		Jedis jedis=new Jedis("123.56.48.63",6379); 
		jedis.auth("218007");
		String value=jedis.get(sessionid);
		jedis.disconnect();
		if(value==null||!value.equals("1")){
			ajaxJson.setSuccess(false).setStatus(99).setMsg("请先登录").setData(returnResult);
		}else{
			try {
				returnResult=provideOrderFormService.confirmRefunds(id);
				ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(returnResult);
			} catch (Exception e) {
				ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(returnResult);
			}
		}
		
		return ajaxJson;
	}
	
	/**
	 * 
	* @Description: 拒绝退款
	* @param id 订单id
	* @param denyRefundsReason 拒绝退款原因
	* @param @return
	* @author Yvonne_MGL 
	* @date 2017年7月21日 上午10:40:14     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "拒绝退款", notes = "拒绝退款")
	@RequestMapping(value = "/denyRefunds", method = RequestMethod.POST)
	public AjaxJson denyRefunds(String id,String denyRefundsReason){
		ReturnResult returnResult=new ReturnResult();
		String sessionid=request.getSession().getId();
		String sessionid1=request.getHeader("Authorization");
		if(sessionid1!=null){
			sessionid=sessionid1.substring(7,sessionid1.length());
		}
		Jedis jedis=new Jedis("123.56.48.63",6379); 
		jedis.auth("218007");
		String value=jedis.get(sessionid);
		jedis.disconnect();
		if(value==null||!value.equals("1")){
			ajaxJson.setSuccess(false).setStatus(99).setMsg("请先登录").setData(returnResult);
		}else{
			try {
				returnResult=provideOrderFormService.denyRefunds(id, denyRefundsReason);
				ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(returnResult);
			} catch (Exception e) {
				ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(returnResult);
			}
		}
		
		return ajaxJson;
	}
	
	/**
	 * 
	* @Description: 修改订单为已读
	* @param id 订单id
	* @param @return
	* @author Yvonne_MGL 
	* @date 2017年7月21日 上午10:40:00     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "修改订单为已读", notes = "修改订单为已读")
	@RequestMapping(value = "/isRead", method = RequestMethod.POST)
	public AjaxJson isRead(String id){
		ReturnResult returnResult=new ReturnResult();
		String sessionid=request.getSession().getId();
		String sessionid1=request.getHeader("Authorization");
		if(sessionid1!=null){
			sessionid=sessionid1.substring(7,sessionid1.length());
		}
		Jedis jedis=new Jedis("123.56.48.63",6379); 
		jedis.auth("218007");
		String value=jedis.get(sessionid);
		jedis.disconnect();
		if(value==null||!value.equals("1")){
			ajaxJson.setSuccess(false).setStatus(99).setMsg("请先登录").setData(returnResult);
		}else{
			try {
				returnResult=provideOrderFormService.isRead(id);
				ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(returnResult);
			} catch (Exception e) {
				ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(returnResult);
			}
		}
		
		return ajaxJson;
	}
	
	/**
	 * 
	* @Description: 将服务商要求的特定类型订单设置为已读
	* @param businessid 服务商id
	* @param state 订单类型
	* @param @return
	* @author Yvonne_MGL 
	* @date 2017年9月13日 下午7:20:33     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "修改订单为已读", notes = "修改订单为已读")
	@RequestMapping(value = "/isReadAll", method = RequestMethod.POST)
	public AjaxJson isReadAll(String businessid,String state){
		String sessionid=request.getSession().getId();
		String sessionid1=request.getHeader("Authorization");
		if(sessionid1!=null){
			sessionid=sessionid1.substring(7,sessionid1.length());
		}
		Jedis jedis=new Jedis("123.56.48.63",6379); 
		jedis.auth("218007");
		String value=jedis.get(sessionid);
		jedis.disconnect();
		if(value==null||!value.equals("1")){
			ajaxJson.setSuccess(false).setStatus(99).setMsg("请先登录").setData(null);
		}else{
			try {
				provideOrderFormService.isReadAll(businessid, state);
				ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(null);
			} catch (Exception e) {
				ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(null);
			}
		}
		return ajaxJson;
	}
	
	/**
	 * 
	* @Description: 查询未读订单数量
	* @param businessid 服务商id
	* @param @return
	* @author Yvonne_MGL 
	* @date 2017年7月21日 上午11:03:29     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "查询未读数量", notes = "查询未读数量")
	@RequestMapping(value = "/findUnread", method = RequestMethod.POST)
	public AjaxJson findUnread(String businessid){
		UnreadOrderNum unreadOrderNum=new UnreadOrderNum();
		String sessionid=request.getSession().getId();
		String sessionid1=request.getHeader("Authorization");
		if(sessionid1!=null){
			sessionid=sessionid1.substring(7,sessionid1.length());
		}
		Jedis jedis=new Jedis("123.56.48.63",6379); 
		jedis.auth("218007");
		String value=jedis.get(sessionid);
		jedis.disconnect();
		if(value==null||!value.equals("1")){
			ajaxJson.setSuccess(false).setStatus(99).setMsg("请先登录").setData(unreadOrderNum);
		}else{
			try {
				unreadOrderNum=provideOrderFormService.findUnread(businessid);
				ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(unreadOrderNum);
			} catch (Exception e) {
				ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(unreadOrderNum);
			}
		}
		
		return ajaxJson;
	}
	
	/**
	 * 
	* @Description: 查询订单发票情况 
	* @param invoiceState 开发票状态
	* @param priceBegin 起始价格
	* @param priceEnd 结束价格
	* @param orderNumber 订单编号
	* @param commodityName 商品名称
	* @param pageNumber  分页页数 ,从0开始
	* @param pageSize  分页每业条数
	* @param @return
	* @author Yvonne_MGL 
	* @date 2017年7月27日 下午5:01:02     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "查询订单发票情况", notes = "查询订单发票情况")
	@RequestMapping(value = "/findInvoiceOrderForm", method = RequestMethod.POST)
	public AjaxJson findInvoiceOrderForm(String invoiceState, Double priceBegin, Double priceEnd,String orderNumber,String commodityName, Integer pageNumber, Integer pageSize,String businessid){
		Map orders = new HashMap();
		String sessionid=request.getSession().getId();
		String sessionid1=request.getHeader("Authorization");
		if(sessionid1!=null){
			sessionid=sessionid1.substring(7,sessionid1.length());
		}
		Jedis jedis=new Jedis("123.56.48.63",6379); 
		jedis.auth("218007");
		String value=jedis.get(sessionid);
		jedis.disconnect();
		if(value==null||!value.equals("1")){
			ajaxJson.setSuccess(false).setStatus(99).setMsg("请先登录").setData(orders);
		}else{
			try {
				orders = provideOrderFormService.findInvoiceOrderForm(invoiceState, priceBegin, priceEnd, orderNumber, commodityName, pageNumber, pageSize,businessid);
				ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(orders);
			} catch (Exception e) {
				ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(orders);
			}
		}
		
		return ajaxJson;
	}
	
	/**
	 * 
	* @Description: 查询发票 
	* @param invoiceid 发票id
	* @param @return
	* @author Yvonne_MGL 
	* @date 2017年7月27日 下午5:20:59     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "查询发票详情", notes = "查询发票详情")
	@RequestMapping(value = "/findPersonalInvoice", method = RequestMethod.POST)
	public AjaxJson findPersonalInvoice(String invoiceid){
		PersonalInvoice personalInvoice=new PersonalInvoice();
		String sessionid=request.getSession().getId();
		String sessionid1=request.getHeader("Authorization");
		if(sessionid1!=null){
			sessionid=sessionid1.substring(7,sessionid1.length());
		}
		Jedis jedis=new Jedis("123.56.48.63",6379); 
		jedis.auth("218007");
		String value=jedis.get(sessionid);
		jedis.disconnect();
		if(value==null||!value.equals("1")){
			ajaxJson.setSuccess(false).setStatus(99).setMsg("请先登录").setData(personalInvoice);
		}else{
			try {
				personalInvoice = provideOrderFormService.findPersonalInvoice(invoiceid);
				ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(personalInvoice);
			} catch (Exception e) {
				ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(personalInvoice);
			}
		}
		return ajaxJson;
	}
	
	/**
	 * 
	* @Description: 服务商为用户开发票 
	* @param orderid 订单id
	* @param @return
	* @author Yvonne_MGL 
	* @date 2017年7月27日 下午5:29:02     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "为用户开发票", notes = "为用户开发票")
	@RequestMapping(value = "/givePersonalInvoice", method = RequestMethod.POST)
	public AjaxJson givePersonalInvoice(String orderid){
		ReturnResult returnResult=new ReturnResult();
		String sessionid=request.getSession().getId();
		String sessionid1=request.getHeader("Authorization");
		if(sessionid1!=null){
			sessionid=sessionid1.substring(7,sessionid1.length());
		}
		Jedis jedis=new Jedis("123.56.48.63",6379); 
		jedis.auth("218007");
		String value=jedis.get(sessionid);
		jedis.disconnect();
		if(value==null||!value.equals("1")){
			ajaxJson.setSuccess(false).setStatus(99).setMsg("请先登录").setData(returnResult);
		}else{
			try {
				returnResult=provideOrderFormService.givePersonalInvoice(orderid);
				ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(returnResult);
			} catch (Exception e) {
				ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(returnResult);
			}
		}
		
		return ajaxJson;
	}
	
	/**
	 * 
	* @Description: 根据条件查询预约空间 
	* @param beginTime 参观起始时间
	* @param endTime 参观结束时间
	* @param likeStr 关键字：模糊查询 联系人，空间名，备注信息
	* @param state 0为未预约  1为已预约
	* @param pageNumber 页数
	* @param pageSize 每页条数
	* @param @return
	* @author Yvonne_MGL 
	* @date 2017年8月15日 上午11:10:08     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "根据条件查询预约空间", notes = "根据条件查询预约空间")
	@RequestMapping(value = "/findSpaceReserve", method = RequestMethod.POST)
	public AjaxJson findSpaceReserve(String beginTime,String endTime,String likeStr,String state,String businessid ,Integer pageNumber, Integer pageSize,String userid){
		Map spaceReserves = new HashMap();
		String sessionid=request.getSession().getId();
		String sessionid1=request.getHeader("Authorization");
		if(sessionid1!=null){
			sessionid=sessionid1.substring(7,sessionid1.length());
		}
		Jedis jedis=new Jedis("123.56.48.63",6379); 
		jedis.auth("218007");
		String value=jedis.get(sessionid);
		jedis.disconnect();
		if(value==null||!value.equals("1")){
			ajaxJson.setSuccess(false).setStatus(99).setMsg("请先登录").setData(spaceReserves);
		}else{
			try {
				spaceReserves = provideSpaceReserveService.findByProperties(beginTime, endTime, likeStr, state,businessid, pageNumber, pageSize,userid);
				ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(spaceReserves);
			} catch (Exception e) {
				ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(spaceReserves);
			}
		}
		return ajaxJson;
	}
	
	/**
	 * 
	* @Description: 根据id查询预约参观详情 
	* @param id
	* @param @return
	* @author Yvonne_MGL 
	* @date 2017年10月14日 上午11:13:00     
	* @return SpaceReserve    
	* @throws 
	 */
	@ApiOperation(value = "根据id查询预约参观详情", notes = "根据id查询预约参观详情")
	@RequestMapping(value = "/findSpaceReserveById", method = RequestMethod.POST)
	public AjaxJson findSpaceReserveById(String id){
		SpaceReserve spaceReserve=null;
		String sessionid=request.getSession().getId();
		String sessionid1=request.getHeader("Authorization");
		if(sessionid1!=null){
			sessionid=sessionid1.substring(7,sessionid1.length());
		}
		Jedis jedis=new Jedis("123.56.48.63",6379); 
		jedis.auth("218007");
		String value=jedis.get(sessionid);
		jedis.disconnect();
		if(value==null||!value.equals("1")){
			ajaxJson.setSuccess(false).setStatus(99).setMsg("请先登录").setData(spaceReserve);
		}else{
			try {
				spaceReserve=provideSpaceReserveService.findSpaceReserveById(id);
				ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(spaceReserve);
			} catch (Exception e) {
				ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(spaceReserve);
			}
		}
		return ajaxJson;
	}
	
	/**
	 * 
	* @Description: 完成预约空间 
	* @param id 预约空间服务id
	* @param @return
	* @author Yvonne_MGL 
	* @date 2017年8月15日 上午11:18:53     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "完成预约空间服务", notes = "完成预约空间服务")
	@RequestMapping(value = "/overReserve", method = RequestMethod.POST)
	public AjaxJson overReserve(String id){
		ReturnResult returnResult=new ReturnResult();
		String sessionid=request.getSession().getId();
		String sessionid1=request.getHeader("Authorization");
		if(sessionid1!=null){
			sessionid=sessionid1.substring(7,sessionid1.length());
		}
		Jedis jedis=new Jedis("123.56.48.63",6379); 
		jedis.auth("218007");
		String value=jedis.get(sessionid);
		jedis.disconnect();
		if(value==null||!value.equals("1")){
			ajaxJson.setSuccess(false).setStatus(99).setMsg("请先登录").setData(returnResult);
		}else{
			try {
				returnResult=provideSpaceReserveService.overReserve(id);
				ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(returnResult);
			} catch (Exception e) {
				ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(returnResult);
			}
		}
		
		return ajaxJson;
	}
	
	/**
	 * 
	* @Description: 申请预约参观 
	* @param reserveTime 参观时间
	* @param contactPerson 联系人
	* @param contactNumber 联系电话
	* @param reserveAmount 参观人数
	* @param remark 备注
	* @param roomid 空间id
	* @param @return
	* @author Yvonne_MGL 
	* @date 2017年8月15日 下午3:10:09     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "申请预约参观", notes = "申请预约参观")
	@RequestMapping(value = "/createProvideSpaceReserve", method = RequestMethod.POST)
	public AjaxJson createProvideSpaceReserve(String reserveTime,String contactPerson,String contactNumber,int reserveAmount,String remark,String roomid,String userid){
		ReturnResult returnResult=new ReturnResult();
		String sessionid=request.getSession().getId();
		String sessionid1=request.getHeader("Authorization");
		if(sessionid1!=null){
			sessionid=sessionid1.substring(7,sessionid1.length());
		}
		Jedis jedis=new Jedis("123.56.48.63",6379); 
		jedis.auth("218007");
		String value=jedis.get(sessionid);
		jedis.disconnect();
		if(value==null||!value.equals("1")){
			ajaxJson.setSuccess(false).setStatus(99).setMsg("请先登录").setData(returnResult);
		}else{
			try {
				returnResult=provideSpaceReserveService.createProvideSpaceReserve(reserveTime, contactPerson, contactNumber, reserveAmount, remark, roomid,userid);
				ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(returnResult);
			} catch (Exception e) {
				ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(returnResult);
			}
		}
		
		return ajaxJson;
	}
	
	/**
	 * 
	* @Description: 查询服务商评价详情 
	* @param businessid 服务商id
	* @param @return
	* @author Yvonne_MGL 
	* @date 2017年8月29日 下午9:57:57     
	* @return AjaxJson    
	* @throws 
	 */
	@ApiOperation(value = "查询服务商评价详情", notes = "查询服务商评价详情")
	@RequestMapping(value = "/getBusinessAppraise", method = RequestMethod.POST)
	public AjaxJson getBusinessAppraise(String businessid, Integer pageNumber, Integer pageSize){
		Map map=new HashMap();
		String sessionid=request.getSession().getId();
		String sessionid1=request.getHeader("Authorization");
		if(sessionid1!=null){
			sessionid=sessionid1.substring(7,sessionid1.length());
		}
		Jedis jedis=new Jedis("123.56.48.63",6379); 
		jedis.auth("218007");
		String value=jedis.get(sessionid);
		jedis.disconnect();
		if(value==null||!value.equals("1")){
			ajaxJson.setSuccess(false).setStatus(99).setMsg("请先登录").setData(map);
		}else{
			try {
				map=provideOrderFormService.getBusinessAppraise(businessid,pageNumber,pageSize);
				ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(map);
			} catch (Exception e) {
				ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(map);
				e.printStackTrace();
			}
		}
		return ajaxJson;
	}
	
	/**
	 * 
	* @Description: 根据服务商id查询服务商的佣金、手续费、保证金总额 
	* @param businessid 服务商id
	* @param @return
	* @author Yvonne_MGL 
	* @date 2017年11月14日 上午10:19:59     
	* @return Map    
	* @throws 
	 */
	@ApiOperation(value = "根据服务商id查询服务商的佣金、手续费、保证金总额", notes = "根据服务商id查询服务商的佣金、手续费、保证金总额")
	@RequestMapping(value = "/getStatistics", method = RequestMethod.POST)
	public AjaxJson getStatistics(String businessid){
		Map map=new HashMap();
		String sessionid=request.getSession().getId();
		String sessionid1=request.getHeader("Authorization");
		if(sessionid1!=null){
			sessionid=sessionid1.substring(7,sessionid1.length());
		}
		Jedis jedis=new Jedis("123.56.48.63",6379); 
		jedis.auth("218007");
		String value=jedis.get(sessionid);
		jedis.disconnect();
		if(value==null||!value.equals("1")){
			ajaxJson.setSuccess(false).setStatus(99).setMsg("请先登录").setData(map);
		}else{
			try {
				map=provideOrderFormService.getStatistics(businessid);
				ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(map);
			} catch (Exception e) {
				ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(map);
				e.printStackTrace();
			}
		}
		return ajaxJson;
	}
	
	/**
	 * 
	* @Description: 初始化returnPreferentialMoney 
	* @param 
	* @author Yvonne_MGL 
	* @date 2017年11月15日 上午10:06:00     
	* @return void    
	* @throws 
	 */
	@ApiOperation(value = "初始化returnPreferentialMoney", notes = "初始化returnPreferentialMoney")
	@RequestMapping(value = "/initializeReturnPreferentialMoney", method = RequestMethod.POST)
	public AjaxJson initializeReturnPreferentialMoney(){
		try {
			provideOrderFormService.initializeReturnPreferentialMoney();
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData("初始化完成");
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData("初始化失败");
		}
		return ajaxJson;
	}

}
